package com.Web.Service.Impl;

import com.Web.DAO.IClassDAO;
import com.Web.DAO.Impl.ClassDAOImpl;
import com.Web.Person.BanJi;
import com.Web.Service.IClassService;
import com.Web.util.PageInfo;

import java.util.List;

public class ClassServiceImpl implements IClassService {

    private IClassDAO classDAO = new ClassDAOImpl();

    @Override
    public List<BanJi> selectAll() {
        List<BanJi> list = classDAO.selectAll();
        return list;
    }

    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        int offset = (pageNo - 1) * pageSize;
        int totalCount = classDAO.selectTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        List<BanJi> list = classDAO.selectByPage(offset,pageSize);
        PageInfo pageInfo = new PageInfo(list, totalPage, pageNo, pageSize);
        return pageInfo;
    }

    @Override
    public void deleteById(int i) {
        classDAO.deleteById(i);
    }

    @Override
    public void add(BanJi banji) {
        classDAO.add(banji);
    }

    @Override
    public BanJi toUpdate(int id) {
        BanJi banji = classDAO.toUpdate(id);
        return banji;
    }

    @Override
    public void update(BanJi banji) {
        classDAO.update(banji);
    }
}
